'use strict';

import React, {Component, PropTypes} from 'react';
import {Grid, Col, Divider} from 'amazeui-react';
import {STRING, API} from '../res';
import {DateTime, SinglePlan} from '../lib';

export default class NoticeDetail extends Component {
	/*
	 * 构造函数。
	 * @param props 属性
	 */
	constructor(props) {
		super(props);
		this.state = {};
	}

	/*
	 * 获取附件列表。
	 * @param value 附件
	 */
	getAttachList(value) {
		value = value !== undefined ? value.split(',') : [];
		value = value.map((x, i) => {
			return (
				<li key={i}>
					<a
						href={API.uploads + x}
						className="am-block"
					>{x}</a>
				</li>
			);
		});

		return <ul>{value}</ul>;
	}

	/*
	 * 渲染。
	 */
	render() {
		let data = this.props.data;
		let attachs = this.getAttachList(data.attach);
		return (
			<div>
				<Grid>
					<Col sm={12}>
						<p>{STRING.relevanceWorkingPlan + '：' + SinglePlan.getId(DateTime.format(data.submitTime, 'YY'), data.planId)}</p>
						<p>{STRING.rectificationDeadline + '：' + (data.rectifyTerm || '')}</p>
						<Divider />
						<h2>{STRING.rectificationContent}</h2>
						<pre>{data.rectifyContent}</pre>
						<h2>{STRING.attach}</h2>
						{attachs}
						<div className={data.advice === '' ? 'am-hide' : 'am-show'}>
							<h2>{STRING.notPassReason}</h2>
							<pre>{data.advice}</pre>
						</div>
						<h2>{STRING.liaisonAdvice}</h2>
						<pre>{data.liaisonAdvice}</pre>
					</Col>
				</Grid>
			</div>
		);
	}
}

NoticeDetail.propTypes = {
	data: PropTypes.object
};
NoticeDetail.defaultProps = {};
